#include <stdio.h>

int main(int argc, const char *argv[])
{
	char buff[128] = {0};
	gets(buff);
	printf("整体翻转前:[%s]\n", buff);
	// 先整体翻转
	int i = 0;
	int j = 0;
	int k = 0;
	char temp = 0;
	while(buff[i])i++;
	i--;
	while(j < i){
		temp = buff[i];
		buff[i] = buff[j];
		buff[j] = temp;
		i--;
		j++;
	}
	printf("整体翻转后:[%s]\n", buff);
	// 逐个单词翻转
	while(1){
		// 定位到单词的开头
		j = k;
		i = k;
		// 找单词的结尾
		while(buff[i] != ' ' && buff[i] != '\0'){
			i++;
		}
		k = i+1; // 保留下一个单词的首下标 也有可能是 '\0' 的后一位
		i--; // 定位到单词的最后一个字符
		// 翻转单个单词
		while(j < i){
			temp = buff[i];
			buff[i] = buff[j];
			buff[j] = temp;
			i--;
			j++;
		}
		if(buff[k-1] == '\0'){
			break;
		}
	}
	printf("全部完成后:[%s]\n", buff);

	return 0;
}
